package top.fzqblog.service;

import android.util.Log;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import top.fzqblog.firstapp.MainActivity;
import top.fzqblog.http.api.RetrofitApi;
import top.fzqblog.model.Meizi;

/**
 * Created by 抽离 on 2017/9/25 0025.
 */

public class RequestApi {

    public void getMeizi(final RequestCallback<Meizi> requestCallback, int page){
        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl("http://gank.io/api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitApi retrofitApi = retrofit.create(RetrofitApi.class);
        Call<Meizi> call = retrofitApi.getMeizi("福利", 20, 1);
        call.enqueue(new Callback<Meizi>() {
            @Override
            public void onResponse(Call<Meizi> call, Response<Meizi> response) {
                Meizi meizi = response.body();
                Log.i("tag", meizi.toString());
                requestCallback.onFinsh(meizi);//此处接口回调
            }

            @Override
            public void onFailure(Call<Meizi> call, Throwable throwable) {
                requestCallback.onError(throwable);
            }
        });
    }

    public interface RequestCallback<T>{
        void onFinsh(T data);

        void onError(Throwable throwable);
    }
}
